package com.ruifu.common.utils;

import com.ruifu.common.config.CodeType;

/**
 * @author nyr
 * @create 2019/10/18
 */
public class ProjectCodeUtils {
    public static String getCode(String type) {
        String randomCode = "";
        // 用字符数组的方式随机
        String model = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        char[] m = model.toCharArray();
        for (int j = 0; j < 8; j++) {
            char c = m[(int) (Math.random() * 36)];
            randomCode = randomCode + c;
        }
        switch (type){
            case CodeType.PROJECT:
                randomCode="P-"+randomCode;//2020.5.13 项目编号前缀Pro->P
                break;
            case CodeType.TASK:
                randomCode="Task-"+randomCode;
                break;
            case CodeType.TEMPLATE_PROJECT:
                randomCode="Tem-Pro-"+randomCode;
                break;
            case CodeType.TEMPLATE_TASK:
                randomCode="Tem-Task-"+randomCode;
                break;
            case CodeType.DOCUMENT:
                randomCode="Doc-"+randomCode;
                break;
            case CodeType.DOCUMENT_TYPE:
                randomCode="DocType_"+randomCode;
                break;
            default:
                break;
        }
        return randomCode;
    }
}
